package com.cscp.javastudy.basic.reflect;

/**
 * 类的初始化
 */
public class ClassInit {

    static {
        System.out.println("main 被加载");
    }

    public static void main(String[] args) throws ClassNotFoundException {
        // 主动加载
        //Son son = new Son();

        // 被动加载
        //Class.forName("com.cscp.javastudy.basic.reflect.Son");

        // 不会产生类的引用方法
        //System.out.println(Son.b);

        // 数组也不会加载类
        //Son[] array = new Son[5];
        System.out.println(Son.M);
    }
}

class Father{
    static int b = 2;
    static {
        System.out.println("父类被加载");
    }
}

class Son extends Father{
    static {
        System.out.println("子类被加载");
        m = 300;
    }

    static int m = 100;
    static final int M = 1;
}
